using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using DeathReportManagement.Services;

namespace DeathReportManagement.Controllers;

[ApiController]
[Route("api/[controller]")]
[Authorize]
public class ApiController : ControllerBase
{
    private readonly HisIntegrationService _hisService;
    
    public ApiController(HisIntegrationService hisService)
    {
        _hisService = hisService;
    }
    
    [HttpGet("patient")]
    public async Task<IActionResult> GetPatientInfo(string? inpatientNo, string? outpatientNo)
    {
        if (string.IsNullOrWhiteSpace(inpatientNo) && string.IsNullOrWhiteSpace(outpatientNo))
        {
            return BadRequest("请提供住院号或门诊号");
        }
        
        var patientInfo = await _hisService.GetPatientInfoAsync(inpatientNo, outpatientNo);
        
        if (patientInfo == null)
        {
            return NotFound("未找到患者信息");
        }
        
        return Ok(patientInfo);
    }
}